Easy to Create, Easy to Change - Easy to use!

Function::Internal

Count Of

count of RELATIONSHIP count of TABLENAME Syntax: count of TABLENAME|RELATIONSHIP [ named "UNIQUE RELATIONSHIP NAME" ] [ with {selection criteria} ]

The count of operator counts how many records in a related table match the specified selection criteria. The result can appear as a list item in the detail area of a report or as a statistic in the summary area at the end of a report.


There's an important difference between the conditional statistical operator count and the relational statistical operator count of. count finds the number of records that satisfy a specified condition among the records being processed. count of calculates the number of matching records related to the records being processed by the script.


Parameters


TABLENAME

You can use Count of directly on a table without a predefined Relationship. Just remember that if there is a Relationship defined that doesn't have an alternative relationship name, this relationship will be named the same and the table and be used. 


RELATIONSHIP

If you use a relationship (alternative name) then the count of will be automatically restricted by the relational restriction. Read under TABLENAME for functionality when using Relationships without alternative relational name.


NAMED "Unique Relationship Name"
You can define an ad hoc named relationship directly in the Count Of function. If you do this you will possibly achieve two things. 1) You will insure against DataEase using a pre-defined relationship with the same name as the table. 2) You can re-use it again in the same script i.e. on a Sum Of etc.


WITH {selection criteria}
With the WITH statement you define the relational restriction of the function. Ex. MyCustomerNR=CustomerNR and MyDate>current date.

Returns/Result


Numeric Value The number of records that fit the relational restriction.

Examples


Example 1

In a field derivation.Simplest type. We have two tables. ThisTable and MyCustomers. We have no relationships defined.

count of MyCustomers 

This will return the number i have.

Example 2

We have two tables.CustomerType and MyCustomers. We have a relationship between them that connect CustomerType and MyCustomers on customer type.There is no Unique Alternative Name for the Relationship. I have 300 records in MyCustomer and 45 of type Good Credit. 

My active record in CustomerType is the Good Credit record.

count of MyCustomers 

This will return the number 45 as I am now using the relationship instead of the table.

count of MyCustomers named "AllRecords" 


Example 3

count of MyCustomers named "NewRel" with RegistrationDate=current date

This will return the number of customers registered today.


Example 4

for MEMBERS with STATE = "CA" ;

list records

LASTNAME in order ;

TOTAL DUE ;

TOTAL DUE > 100 : item count ;

count of RESERVATIONS with ( TOTAL DUE > 1500) .

end


This script tells DataEase: (1) Process all the MEMBERS records of members living in California, (2) list the LAST NAME and TOTAL DUE field from each MEMBERS record, (3) for each member, display a YES or NO answer indicating if the member's TOTAL DUE is greater than $100, (4) count the total number of members whose TOTAL DUE is greater than $100 and display this total as a statistic at the end of the report output (this is generated by the count operator), and (5) count the number of related RESERVATIONS records that have a TOTAL DUE greater than $1500, and display this number as a list item for each member (this is generated by the count of operator).


Reference

count of

Type

Relational Statistical Operator

Purpose

The count of operator counts how many records in a related table match the specified selection criteria. The result can appear as a list item in the detail area of a report or as a statistic in the summary area at the end of a report.

There's an important difference between the conditional statistical operator count and the relational statistical operator count of. count finds the number of records that satisfy a specified condition among the records being processed. count of calculates the number of matching records related to the records being processed by the script.

Syntax

count of TABLENAME|RELATIONSHIP

 [named "UNIQUE RELATIONSHIP NAME" ]

 [with ( selection criteria) ] ;|.

 

Example

for MEMBERS with STATE = "CA" ;

list records

LASTNAME in order ;

TOTAL DUE ;

TOTAL DUE > 100 : item count ;

count of RESERVATIONS with ( TOTAL DUE > 1500) .

end

 

This script tells DataEase: (1) Process all the MEMBERS records of members living in California, (2) list the LAST NAME and TOTAL DUE field from each MEMBERS record, (3) for each member, display a YES or NO answer indicating if the member's TOTAL DUE is greater than $100, (4) count the total number of members whose TOTAL DUE is greater than $100 and display this total as a statistic at the end of the report output (this is generated by the count operator), and (5) count the number of related RESERVATIONS records that have a TOTAL DUE greater than $1500, and display this number as a list item for each member (this is generated by the count of operator).

See Also


Sum Of Highest Of Lowest Of Mean Of

On the forum about Count Of

count of not updated in a while loop

Hi there,I have this simple algorithm to implement:1. Check how many working days there are between date x and date x - y days (y = 3);NOTE: I have a special table listing all days till 2050: the day has...

Product: Dataease [{8}]FIVE. Written by George Washington 16/10/15 at 07:08:04

Re:count of not updated in a while loop

Downalod Sample! This is one of the 20 least well known "bugs" in DataEase, but it is KNOWN ;-) There has been much debate on this as...

Product: Dataease [{8}]FIVE. Written by DataEase 16/10/15 at 12:07:02

Re:Re:count of not updated in a while loop

Thanks that works!...

Product: Dataease [{8}]FIVE. Written by George Washington 16/10/15 at 14:36:15

How do I do a count of the number of yes's in yes/no fields

[@EOF@]...

Product: LegEasy DOS. Written by Simon Lazarus 01/05/20 at 13:13:05

Re:How do I do a count of the number of yes's in yes/no fields

Depends a little where you want to count it.You use a relationship.in DQL you can doretval := Count of MyTable with FieldX=Yes .If you are to do this in a virtual field you need to define a relationship it can be be...

Product: LegEasy DOS. Written by DataEase 01/05/20 at 13:22:09

Re:Re:How do I do a count of the number of yes's in yes/no fields

Thanks for the prompt response.This works fine for a virtual field when I have added the support field to the relationship.I am trying to compile responses from surveys and have 20 different fields i need to have individual yes totals on...

Product: LegEasy DOS. Written by Simon Lazarus 01/05/20 at 13:38:55

Re:Re:Re:How do I do a count of the number of yes's in yes/no fields

Then you need 20 relationships if you are doing this in the form.The support field can be used in all the relationships and then the other side is the individual fields.You obviously have to use alternate relationship names....

Product: LegEasy DOS. Written by DataEase 01/05/20 at 17:20:18

Re:Re:Re:Re:How do I do a count of the number of yes's in yes/no fields

Alternative relationship names works great - Thanks...

Product: LegEasy DOS. Written by Simon Lazarus 04/05/20 at 13:07:53

Re:Re:Re:Re:Re:How do I do a count of the number of yes's in yes/no fields

20 relationships is 'ugly' and the counting can be slow if you have a lot of records...I would create a hidden integer field with a derivation of 'if( fieldname01 = 'yes', 1 , 0 ) for each of the 20 fields.Then just do a 'sum of tablenam...

Product: LegEasy DOS. Written by Earl Wertheimer 05/05/20 at 20:29:59

On the blog about Count Of